#!/bin/bash
set -e

FWPATH="../"
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

################## HW 46 & 47 #######################

COPYDIR=46_o_47
rm $COPYDIR/*

# default
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin

# 33k
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DVIN_R1=33000.0 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_33k.bin

# 0005ohm
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DCURRENT_SHUNT_RES=0.0005 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_0005ohm.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_ws2811.bin

# ws2811_33k
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DWS2811_ENABLE=1 -DVIN_R1=33000.0 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_ws2811_33k.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_46"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin

#################### HW 48 ########################

COPYDIR=48
rm $COPYDIR/*

# default
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin

# 0005ohm
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DCURRENT_SHUNT_RES=0.0005 -DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_0005ohm.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_ws2811.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_48"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin

#################### HW 410 & 411 & 412 ########################

COPYDIR=410_o_411_o_412
rm $COPYDIR/*

# default
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin

# default with HW limits disables
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_410 -DDISABLE_HW_LIMITS"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default_no_hw_limits.bin

# 0005ohm
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DCURRENT_SHUNT_RES=0.0005 -DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_0005ohm.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_ws2811.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_410"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin

#################### HW 60 ########################

COPYDIR=60
rm $COPYDIR/*

# default
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_60"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin

# default with HW limits disables
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_60 -DDISABLE_HW_LIMITS"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default_no_hw_limits.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_60"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_ws2811.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_60"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin

# Clean
cd $FWPATH
make clean
cd $DIR

#################### HW DAS_RS ########################

COPYDIR=DAS_RS
rm $COPYDIR/*

# default
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_DAS_RS"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin

# Clean
cd $FWPATH
make clean
cd $DIR

#################### HW 75_300 ########################

COPYDIR=75_300
rm $COPYDIR/*

# default
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_75_300"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default.bin

# default with HW limits disables
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DHW_VERSION_75_300 -DDISABLE_HW_LIMITS"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_default_no_hw_limits.bin

# ws2811
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DWS2811_ENABLE=1 -DHW_VERSION_75_300"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_ws2811.bin

# servoout
cd $FWPATH
touch conf_general.h
make -j8 build_args="-DSERVO_OUT_ENABLE=1 -DHW_VERSION_75_300"
cd $DIR
cp $FWPATH/build/BLDC_4_ChibiOS.bin $COPYDIR/VESC_servoout.bin

# Clean
cd $FWPATH
make clean
cd $DIR

